/*
 * Copyright (c) 2006, 2022, webrx.cn All rights reserved.
 *
 */
package cn.webrx.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * <p>Project: javaweb - CheckLogin
 * <p>Powered by webrx On 2022-03-10 09:54:51
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
@WebServlet("/check")
public class CheckLogin extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        String a = req.getParameter("account");
        String p = req.getParameter("password");
        HttpSession session = req.getSession();

        //登录成功
        session.setAttribute("user", a);

        resp.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        PrintWriter out = resp.getWriter();
        out.println("<!DOCTYPE html><html lang=\"zh-CN\"><head>");
        out.println("<meta charset=\"utf-8\">");
        out.println("<title>管理系统</title>");
        out.println("<meta http-equiv=\"refresh\" content=\"2;url=/\">");
        out.println("</head><body>");
        out.printf("<h3>欢迎：%s，登录成功。</h3>", a);
        out.println("</body></html>");
        out.println("</html>");
        out.flush();
        out.close();
    }
}
